# -*- coding:UTF-8 -*-
from RPi import GPIO
from raspberryPi.Constant import *


class Track:
    def __init__(self):
        GPIO.setup(TrackSensorLeftPin1, GPIO.IN)
        GPIO.setup(TrackSensorLeftPin2, GPIO.IN)
        GPIO.setup(TrackSensorRightPin1, GPIO.IN)
        GPIO.setup(TrackSensorRightPin2, GPIO.IN)
        self.infrared_track_value = ''

    def trackLine(self):
        """
        检测到黑线时循迹模块相应的指示灯亮，端口电平为LOW
        未检测到黑线时循迹模块相应的指示灯灭，端口电平为HIGH
        :return: None
        """
        TrackSensorLeftValue1 = GPIO.input(TrackSensorLeftPin1)
        TrackSensorLeftValue2 = GPIO.input(TrackSensorLeftPin2)
        TrackSensorRightValue1 = GPIO.input(TrackSensorRightPin1)
        TrackSensorRightValue2 = GPIO.input(TrackSensorRightPin2)
        infrared_track_value_list = ['0', '0', '0', '0']
        infrared_track_value_list[0] = str(1 ^ TrackSensorLeftValue1)
        infrared_track_value_list[1] = str(1 ^ TrackSensorLeftValue2)
        infrared_track_value_list[2] = str(1 ^ TrackSensorRightValue1)
        infrared_track_value_list[3] = str(1 ^ TrackSensorRightValue2)
        self.infrared_track_value = ''.join(infrared_track_value_list)
